package bma.common.langutil.jdbc;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.Date;

import bma.common.langutil.core.Function;
import bma.common.langutil.core.Preconditions;

public class JdbcTypeMapper implements Function<Object, Integer> {

	public static final JdbcTypeMapper O = new JdbcTypeMapper();

	@Override
	public Integer apply(Object input) {
		Preconditions.checkNotNull(input);
		if (input instanceof Number) {
			return ((Number) input).intValue();
		}
		if (input == Integer.class)
			return Types.INTEGER;
		if (input == String.class)
			return Types.VARCHAR;
		if (input == Long.class)
			return Types.BIGINT;
		if (input == Float.class)
			return Types.FLOAT;
		if (input == Double.class)
			return Types.DOUBLE;
		if (input == Timestamp.class)
			return Types.TIMESTAMP;
		if (input == Date.class)
			return Types.DATE;
		throw new IllegalArgumentException("unknow type(" + input + ")");
	}
}
